<?php
//////////////////////////////////////////////////////
// GPAC Database is Copyright 2002 Colin Todd       //
// Written by Colin Todd - All rights reserved.     //
//                                                  //
// colintodd@myfastmail.com                         //
//////////////////////////////////////////////////////


$alphabet = @$_GET['alphabet'];
$listfilter = "";
$listfilter = @$_GET['listfilter'];
$WhereFilter = "";
$listfilter_htmlcode =	 "listfilter=$listfilter&amp;";

if ($alphabet==null or $alphabet == ""){
    $alphabet="all";
}
$alphabet_htmlcode = 'alphabet='.$alphabet.'';


$link = 'index.php?view=Fmly_az_list?'.$alphabet_htmlcode.'&amp;';
//print_r($_GET);
$FamilyId = $_GET['FamilyId'];
$IndividualId = @$_GET['IndividualId'];

$WhereFilter = $PACTS_cfg->getListHeader($listfilter_htmlcode,$alphabet,"index.php?view=Fmly_az_list&amp;","index.php?view=Fmly_allentries","Families",$listfilter,'FamilyId='.$FamilyId);

if (strlen($FamilyId) > 0) {

    $sql = 'SELECT *, CommentText as FmlyCommentText FROM '.$PACTS_cfg->familytablename.' WHERE FamilyId='.$FamilyId.';';
    $result = mysql_query($sql,$PACTS_cfg->dblink);

    $links = mysql_fetch_array($result);


    $FamilyName = $PACTS_cfg->getFormattedFamilyShortName($FamilyId," ");

    //   $address  = $PACTS_cfg->getFormattedResidentialAddress($FamilyId,"<br />",TRUE,FALSE,FALSE,FALSE,TRUE);
    $HomePhone = $PACTS_cfg->getFormattedHomePhoneNumber($FamilyId," ",FALSE, TRUE,TRUE);
    $HomeFax = $PACTS_cfg->getFormattedHomeFaxNumber($FamilyId," ",FALSE, TRUE,TRUE);
    $Comment = nl2br ($links["FmlyCommentText"]);

    $ResidentialAddress = $PACTS_cfg->getFormattedResidentialAddress($FamilyId,"<br />",TRUE,FALSE,FALSE,FALSE,TRUE);

    if ($links["MailingAddressIndicator"]=='Y')
    {
        $PostalAddress = $ResidentialAddress;
    }
    else
    {
        $PostalAddress = $PACTS_cfg->getFormattedPostalAddress($FamilyId,"<br />",TRUE,FALSE,FALSE,TRUE);
    }



    echo '<p />'."\n";
    echo '<div id="details-section">'."\n";
    echo '<div id="viewHeading">'."\n";
    echo $PACTS_cfg->getFmlyNavBar($IndividualId, $FamilyId."&amp;".$listfilter_htmlcode.$alphabet_htmlcode, FALSE, TRUE, TRUE, "index.php?view=Fmly_az_index&amp;","",TRUE,TRUE,"",FALSE);

    echo '<p class="IndvName">'.$FamilyName.' Family:</p>'."\n";
    //    echo '<p id="IndvRole">'.$Gender.' '.$role.'</p>'."\n";
    echo '<hr class="left200px" />'."\n";
    //    echo '</ul>'."\n";
    echo '</div>'."\n";


    echo '<div id="viewDetailsC1">'."\n";
    echo '<ul>'."\n";
    echo '<li class="colw50pc"><p class="viewDetailsHeader">Home Address:</p><p class="viewDetailsData">'.$ResidentialAddress.'</p></li>'."\n";
    echo '<li class="colw50pc"><p class="viewDetailsHeader">Postal Address:</p><p class="viewDetailsData">'.$PostalAddress.'</p></li>'."\n";
    echo '</ul>'."\n";
    echo '<ul>'."\n";
    echo '<li class="colw50pc"><p class="viewDetailsHeader">Home Phone:</p><p class="viewDetailsData">'.$HomePhone.'</p></li>'."\n";
    if(strlen($HomeFax)>0) {echo '<li class="colw50pc"><p class="viewDetailsHeader">Home Fax:</p><p class="viewDetailsData">'.$HomeFax.'</p></li>'."\n";}
    echo '</ul>'."\n";
    echo '<ul>'."\n";
    echo '<li class="colw100pc"><p class="viewDetailsHeader">Comments:</p><p class="viewDetailsData">'.str_replace("\n", "<br />", $Comment).'</p></li>'."\n";
    echo '</ul>'."\n";

    if(strlen($links["FamilyPhoto"])>0) {

        echo '<ul>'."\n";
        echo '<li class="colw100pc"><p class="viewDetailsHeader">Family Photo:</p>'."\n";
        echo '<p class="viewDetailsData">'."\n";
        echo '<a href="index.php?view=display_image_full&amp;FamilyId='.$FamilyId.'" >'."\n";
        echo '<img src="index.php?view=display_image_thumb&amp;FamilyId='.$FamilyId.'&amp;width=150" alt="Open picture in new window" />'."\n";
        echo '</a>'."\n";

        echo '</p></li>'."\n";

        echo '</ul>'."\n";
    }
    echo '</div>'."\n";



    //////////////////////////////

    echo '<p class="IndvName">Family Members:</p>'."\n";


    $sql = "SELECT * FROM (((".$PACTS_cfg->individualtablename.") LEFT JOIN ".$PACTS_cfg->gendertablename." ON ".$PACTS_cfg->individualtablename.".GenderCode = ".$PACTS_cfg->gendertablename.".GenderCode) LEFT  JOIN ".$PACTS_cfg->titletablename." ON ".$PACTS_cfg->individualtablename.".Title = ".$PACTS_cfg->titletablename.".Title) LEFT  JOIN ".$PACTS_cfg->roletypetablename." ON ".$PACTS_cfg->individualtablename.".RoleTypeCode = ".$PACTS_cfg->roletypetablename.".RoleTypeCode WHERE ".$PACTS_cfg->individualtablename.".FamilyId=".$FamilyId." ORDER BY ".$PACTS_cfg->individualtablename.".RoleTypeCode DESC, ".$PACTS_cfg->individualtablename.".GenderCode DESC;";
    //echo $sql;
    $result = mysql_query($sql,$PACTS_cfg->dblink);
    $sql_cnt = "SELECT Count(*) as Count FROM $PACTS_cfg->individualtablename WHERE FamilyId=$FamilyId";
    $result_cnt = mysql_query($sql_cnt,$PACTS_cfg->dblink);
    $row_cnt = mysql_fetch_assoc($result_cnt);

    echo '<table class="listType1">'."\n";//cellpadding=2 cellspacing=1 border=0>";

    $alternate = "2";
    while ($row = mysql_fetch_array($result)) {

        $IndividualId = $row["IndividualId"];
        $FamilyId = $row["FamilyId"];
        $firstname = $row["FirstName"];
        $lastname = $row["Surname"];
        $role= $row["RoleTypeCode"];
        $Gender = $PACTS_cfg->getLookValue($PACTS_cfg->gendertablename, "GenderCode", $row["GenderCode"], "Description");

        //	echo "<tr><td>GEnder $Gender ".$links["GenderCode"]." </td></tr>";

        echo $PACTS_cfg->getIndvNavBar($IndividualId, $FamilyId."&amp;".$listfilter_htmlcode.$alphabet_htmlcode, TRUE, TRUE, TRUE, "Fmly_view","",TRUE,"".$lastname.", ".$firstname." <i>(".trim($Gender." ".$role).")</i>");
        echo"</tr>";
    }
    echo "</table>";
    echo '</div>'."\n";
    ///////////////////////////////
} else {
    echo "You need to select an ID number of a data entry";
}
?>